package com.goldenKey.admin.controller;

import com.goldenKey.common.pojo.result.R;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.goldenKey.common.pojo.po.Orders;
import com.goldenKey.admin.service.IOrdersService;

/**
 * @Author: 吃我一钊
 * @Description: 控制层
 * @Date: 2025/02/02
 */
@RestController
@RequestMapping("/orders")
public class OrdersController {

	@Autowired
	private IOrdersService ordersService;

	/**
	 * 新增数据
	 * @param orders
	 * @return
	 */
	@PostMapping("/save")
	public R<Void> save(@RequestBody Orders orders) {
		ordersService.save(orders);
		return R.ok();
	}

	/**
	 * 根据id删除
	 * @param ordersId
	 * @return
	 */
	@DeleteMapping("/deleteById/{ordersId}")
	public R<Void> deleteById(@PathVariable("ordersId") Integer ordersId) {
		ordersService.removeById(ordersId);
		return R.ok();
	}

	/**
	 * 根据id修改数据
	 * @param orders
	 * @return
	 */
	@PutMapping("/updateById")
	public R<Void> updateById(@RequestBody Orders orders) {
		ordersService.updateById(orders);
		return R.ok();
	}

	/**
	 * 根据id查询数据
	 * @param ordersId
	 * @return
	 */
	@GetMapping("/getById/{ordersId}")
	public R<Orders> getById(@PathVariable("ordersId") Integer ordersId) {
		Orders orders = ordersService.getById(ordersId);
		return R.ok(orders);
	}
	/**
	 * 查询所有数据
	 * @return
	 */
	@GetMapping("/list")
	public R<List<Orders>> list() {
		List<Orders> ordersList = ordersService.list();
		return R.ok(ordersList);
	}

}